<include file="/public/header" />
<style>
    .layui-table-cell {
        overflow: visible;
        text-overflow: inherit;
        white-space: normal;
        height: auto;
        /*在这里设置行高没用*/
    }
</style>
<div class="layui-fluid">
    <div class="layui-card">
        <!-- // 默认操作按钮 -->
        <div class="layui-card-header layadmin-card-header-auto ">
            <div class="layui-form">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <div class="layui-input-inline">
                            <select name="iswarn">
                                <option value="">{:__('全部')}</option>
                                <option value="1">{:__('库存低于预警')}</option>
                                <option value="2">{:__('库存高于预警')}</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <div class="layui-input-inline">
                            <select name="seriestype">
                                <option value="">{:__('产品类型')}</option>
                                <foreach $seriestype as $v>
                                    <option value="{$v.id}">{$v.title}</option>
                                </foreach>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <div class="layui-input-inline ">
                            <input name="title" class="layui-input" type="text" placeholder="{:__('关键字搜索')}" />
                        </div>
                    </div>

                    <div class="layui-inline">
                        <!-- // 默认搜索 -->
                        <button class="layui-btn icon-btn" lay-filter="formSearch" lay-submit><i
                                class="layui-icon layui-icon-search"></i>{:__('搜索')}</button>
                        <!-- // 打开添加页面 -->
                        <button data-area="762px,95%" class="layui-btn icon-btn" lay-open=""
                            data-title="{:__('添加')}{:__('产品')}" data-url="{:url('/system/product/add')}" callback="add"
                            lay-event="add">
                            <i class="layui-icon layui-icon-add-1"></i>{:__('添加')}
                        </button>
                        <div class="layui-divider layui-divider-vertical"></div>
                    </div>
                </div>
            </div>
        </div>

        <!-- // 创建数据实例 -->
        <table id="lay-tableList" lay-filter="lay-tableList"></table>
    </div>
</div>
<!-- // 添加编辑数据 -->
<script type="text/html" id="editforms2">
    <div class="layui-fluid layui-bg-white" >
        <form class="layui-form layui-form-fixed" lay-filter="editforms2" >
        <input type="text" name="id" hidden="">              

        <div class="layui-form-item">
            <label class="layui-form-label"><font color="red">* </font>操作类型:</label>
            <div class="layui-input-block">
                <input type="radio" name="type" value="1" title="增加" checked>
                <input type="radio" name="type" value="2" title="减少">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">{:__('数量')}</label>
            <div class="layui-input-block">
                <input name="number" placeholder="{:__('请输入数量')}" type="number" class="layui-input"  lay-verify="required" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><font color="red">* </font>说明:</label>
            <div class="layui-input-block">
                <textarea name="desc" placeholder="请输入文本内容" class="layui-textarea" lay-verify="required" ></textarea>
            </div>
        </div>  
        <div class="layui-footer layui-form-item layui-center "  >
            <button class="layui-btn layui-btn-primary" type="button" sa-event="closePageDialog" >{:__('取消')}</button>
            <button class="layui-btn" lay-edit="{:url('/system/product/packagedit')}" lay-filter="submitPage" data-reload="self" lay-submit>{:__('提交')}</button>
        </div>
        </form>
    </div>
</script>
<!-- // 添加编辑数据 -->
<script type="text/html" id="editforms">
    <div class="layui-fluid layui-bg-white" >
        <form class="layui-form layui-form-fixed" lay-filter="editforms" >
        <input type="text" name="id" hidden="">              

        <div class="layui-form-item">
            <label class="layui-form-label"><font color="red">* </font>操作类型:</label>
            <div class="layui-input-block">
                <input type="radio" name="type" value="1" title="增加" checked>
                <input type="radio" name="type" value="2" title="减少">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">{:__('数量')}</label>
            <div class="layui-input-block">
                <input name="number" placeholder="{:__('请输入数量')}" type="number" class="layui-input"  lay-verify="required" />
            </div>
        </div>  
        <div class="layui-form-item">
            <label class="layui-form-label"><font color="red">* </font>说明:</label>
            <div class="layui-input-block">
                <textarea name="desc" placeholder="请输入文本内容" class="layui-textarea" lay-verify="required" ></textarea>
            </div>
        </div>  
        <div class="layui-footer layui-form-item layui-center "  >
            <button class="layui-btn layui-btn-primary" type="button" sa-event="closePageDialog" >{:__('取消')}</button>
            <button class="layui-btn" lay-edit="{:url('/system/product/skuedit')}" lay-filter="submitPage" data-reload="self" lay-submit>{:__('提交')}</button>
        </div>
        </form>
    </div>
</script>
<!-- // 列表工具栏 -->
<script type="text/html" id="tableBar">
    <a class="layui-table-text" data-title="{:__('库存操作')}"  data-url="#editforms" lay-event="edit">{:__('库存操作')}</a>
    <div class="layui-divider layui-divider-vertical"></div>
    <a class="layui-table-text" data-title="{:__('库存记录')} {{d.title}}" 
    data-area="762px,95%" data-url="{:url('/system/product/log')}?id={{d.id}}"  lay-event="edit" >{:__('库存记录')}</a>
    <div class="layui-divider layui-divider-vertical"></div>
    <a class="layui-table-text" data-title="{:__('包装操作')}"  data-url="#editforms2" lay-event="edit">{:__('包装操作')}</a>
    <a class="layui-table-text" data-title="{:__('库存记录')} {{d.title}}" 
    data-area="762px,95%" data-url="{:url('/system/product/packageLog')}?id={{d.id}}"  lay-event="edit" >{:__('包装记录')}</a>
    <div class="layui-divider layui-divider-vertical"></div>

<div class="layui-divider layui-divider-vertical"></div>
    <a class="layui-table-text" data-title="{:__('编辑')} {{d.title}}" 
        data-area="762px,95%" data-url="{:url('/system/product/edit')}?id={{d.id}}"  lay-event="edit" >{:__('编辑')}</a>
    <div class="layui-divider layui-divider-vertical"></div>
    <a class="layui-table-text" data-url="{:url('/system/product/del')}?id={{d.id}}" lay-event="del">{:__('删除')}</a>
</script>

<!-- // 列表状态栏 -->
<script type="text/html" id="columnType">
    {{#  if(d.type ==1){ }}
    快递发货
    {{# }if(d.type ==2) { }}
    门店兑换
    {{#  } }}
</script>
<script type="text/html" id="columnHot">
    {{#  if(d.ishot ==1){ }}
    正常
    {{# }if(d.ishot ==2) { }}
    推荐
    {{#  } }}
</script>
<script type="text/html" id="columnStatus">
    {{#  if(d.status ==1){ }}
    待上架
    {{# }if(d.status ==2) { }}
    已上架
    {{#  } }}
</script>
<include file="/public/footer" />
<script>
    layui.use(['admin', 'layedit', 'table', 'form', 'content'], function () {
        var admin = layui.admin;
        var table = layui.table;
        var form = layui.form;
        var layedit = layui.layedit;
        var content = layui.content;
        /*
         * 初始化表格
        */
        var isTable = table.render({
            elem: "#lay-tableList"
            , url: "{:url('/system/product/index')}"
            , page: true
            , limit: 18
            , cols: [[
                { type: 'checkbox', width: 50 },
                { field: 'id', align: 'center', sort: true, width: 80, title: 'ID' },
                {
                    field: 'title', align: 'left', title: '{:__("产品名称")}', templet: function (d) {
                        if (d.stock <= d.warnings) {
                            return '<span style="color:red">' + d.title + '</span>'
                        } else {
                            return d.title;
                        }
                    }
                },
                { field: 'codes', align: 'left', title: '{:__("编码")}' },
                { field: 'spec', align: 'left', title: '{:__("规格")}' },
                { field: 'remark', align: 'left', title: '{:__("备注")}' },
                { field: 'stock', align: 'left', title: '{:__("库存")}' },
                { field: 'package', align: 'left', title: '{:__("包装袋")}' },
                {
                    field: 'images', align: 'center', width: 100, templet: function (d) {
                        return d.images[0] ? '<div><img src="' + d.images[0] + '" width="50" height="50" lay-image-hover="" ></div>' : '<div></div>';
                    }, title: '图片'
                },
                { field: 'types_name', align: 'left', title: '{:__("产品类型")}' },
                { field: 'price', align: 'left', title: '{:__("价格")}' },
                { field: 'create_time', align: 'center', width: 180, title: '{:__("添加时间")}' },
                { align: 'center', toolbar: '#tableBar', width: 160, title: '{:__("操作")}' },
            ]],
            done: function () {
                //当数据渲染完后，执行的回调
            }
        })
    })
</script>